package tests;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.net.URLCodec;

import com.wsc.crawler.URLutils.RefineURL;


public class RefineUrlTest {
public static void main(String...as) throws MalformedURLException, UnsupportedEncodingException{
	URL url=new URL("http://www.jamendo.com/en/login into/signup#hello");
	URL l=RefineURL.removeFragments(url);
	System.out.println("Removed Fragment ::"+l.toString());
	l=RefineURL.DecodeURL(url,"UTF-16");
	System.out.println("Decoded URL::"+l.toString());
	l=RefineURL.refineURL(url, "UTF-16");
	System.out.println("Refined URL::"+l.toString());
	
	ArrayList<URL> a=new ArrayList<URL>();
	a.add(new URL("https://accounts.google.com/SignUp?service=lso&continue=https%3A%2F%2Faccounts.google.com%2Fo%2Foauth2%2Fauth%3Fscope%3Dhttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile%2Bhttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email%26response_type%3Dcode%26access_type%3Doffline%26redirect_uri%3Dhttp%3A%2F%2Fwww.jamendo.com%2Flogin%2Fgoogle%26approval_prompt%3Dauto%26client_id%3D1028708766187.apps.googleusercontent.com%26hl%3Den-GB%26from_login%3D1%26as%3D6ec9cd0ec8820c81&ltmpl=popup"));
	a.add(new URL("http://www.jamendo.com/r.php?fbconnect=1&api_key=113060231172&app_id=113060231172&cancel_url=http%3A%2F%2Fwww.jamendo.com%2Fen%2Flogin%2Ffacebook%3Ferror_reason%3Duser_denied%26error%3Daccess_denied%26error_description%3DThe%2Buser%2Bdenied%2Byour%2Brequest.%26state%3D242d3ac74d1241719b32f9bef11bec4d&popup=1&locale=en_GB&display=popup"));
	a.add(new URL("http://www.jamendo.com/en/changelang?redirect=http%3A%2F%2Fartists.jamendo.com%2Fen%2Fhome"));
	a.add(new URL("https://twitter.com/signup?context=oauth&oauth_token=K7TldeHi2OdDacDSlWYqS6ytKNYWKAWyLMKyYdJs"));
	a.add(new URL("http://www.jamendo.com/en/login/signup#hello"));
	a.add(new URL("http://appworld.blackberry.com/webstore/content/36433?lang=fr"));

	
	URL n=new URL("http://tools.bestmovies21.com/index.php?s=How To Train Prism En&updatepopularity=1");
	System.out.println("Before "+n.toString());
	System.out.println("After "+RefineURL.encodeQueryPart(n).toString());
}

public static int nthOccurrence(String str, char c, int n) {
    int pos = str.indexOf(c, 0);
    while (n-- > 0 && pos != -1)
        pos = str.indexOf(c, pos+1);
    return pos;
}
}
